package com.itgo.codegen.util;

import java.io.StringWriter;
import java.util.Properties;

import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;

import com.itgo.codegen.bean.TemplateBean;

public class TemplateUtil {

	private static final VelocityEngine ve = new VelocityEngine() ;
	static{
		Properties p = new Properties() ;
		p.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
	    p.setProperty(Velocity.OUTPUT_ENCODING, "UTF-8");
		ve.init( p ); 
	}
	public static String merge( String templateName , TemplateBean bean ){
		Template template = ve.getTemplate( templateName ) ;
		StringWriter swriter = new StringWriter() ;
		template.merge( bean.getContext() , swriter );
		return swriter.toString() ;
	}
}
